#include "../Tools/GLHeaders.hpp"
#include "ModelRightLeg.hpp"
#include <cmath>

ModelRightLeg::ModelRightLeg(void){
	activate = false;	
  list_id = glGenLists(1); // create one DisplayList
  glNewList(list_id, GL_COMPILE);
  GLUquadricObj *quadratic = gluNewQuadric();
  gluQuadricNormals(quadratic, GLU_SMOOTH);

  GLfloat pt00[] = {-0.75f,-6.75f, 0.75f};
  GLfloat pt01[] = { 0.75f,-6.75f, 0.75f};
  GLfloat pt02[] = { 0.75f,-6.75f,-0.75f};
  GLfloat pt03[] = {-0.75f,-6.75f,-0.75f};

  GLfloat pt10[] = {-0.5f,-0.5f, 0.5f};
  GLfloat pt11[] = { 0.5f,-0.5f, 0.5f};
  GLfloat pt12[] = { 0.5f,-0.5f,-0.5f};
  GLfloat pt13[] = {-0.5f,-0.5f,-0.5f};

  glBegin(GL_TRIANGLES);
  glNormal3f( 0.0f, 0.0f, 1.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt00); // front
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt01);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt11);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt11);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt10);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt00);

  glNormal3f( 1.0f, 0.0f, 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt01); // right
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt02);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt12);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt12);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt11);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt01);

  glNormal3f( 0.0f, 0.0f,-1.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt02); // back
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt03);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt13);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt13);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt12);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt02);

  glNormal3f(-1.0f, 0.0f, 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt03); // left
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt00);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt10);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt10);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt13);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt03);

  glNormal3f( 0.0f, 1.0f, 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt10); // top
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt11);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt12);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt12);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt13);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt10);

  glNormal3f( 0.0f,-1.0f, 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt02); // botton
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt01);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt00);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt00);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt03);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt02);
  glEnd();
  glTranslatef(0.0f, -7.0f, 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);
  gluSphere(quadratic, 1.0f, 16, 16);
  glTranslatef(0.0f, 7.0f, 0.0f);
  glEndList();
 }

ModelRightLeg::~ModelRightLeg(void){
  glDeleteLists(list_id,1);
}

void ModelRightLeg::Draw(void){
	glPushAttrib(GL_COLOR_BUFFER_BIT|GL_CURRENT_BIT|GL_TEXTURE_BIT);	
	glDisable(GL_TEXTURE_2D); 
	if(activate)
		glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
	else
		glColor4f(0.0f, 1.0f, 0.0f, 1.0f);

  glCallList(list_id);
	glPopAttrib();
}

void ModelRightLeg::Activate(void){
	activate = true;
}

void ModelRightLeg::Desactivate(void){
	activate = false;
}
